package com.xmindguoguo.boot.config;

import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.session.Configuration;

import com.baomidou.mybatisplus.entity.TableInfo;
import com.baomidou.mybatisplus.mapper.AutoSqlInjector;


public class mySqlInjector extends AutoSqlInjector{

    @Override
    public void inject(Configuration configuration, MapperBuilderAssistant builderAssistant, Class<?> mapperClass,
                       Class<?> modelClass, TableInfo table) {
        /* 添加一个自定义方法 */
        selectOneByProperty(mapperClass, modelClass, table);
    }

    public void selectOneByProperty(Class<?> mapperClass, Class<?> modelClass, TableInfo table) {

		/* 执行 SQL ，动态 SQL 参考类 SqlMethod */
        String sql = "select * from " + table.getTableName();

		/* mapper 接口方法名一致 */
        String method = "selectOneByProperty";
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
      //  this.addDeleteMappedStatement(mapperClass, method, sqlSource);
        this.addSelectMappedStatement(mapperClass, method, sqlSource, modelClass, table);
    }

}
